/**
 * https://vitejs.dev/
 *
 * https://github.com/vitejs/vite/blob/main/docs/config/index.md
 * https://github.com/alloc/vite-plugin-legacy（需要兼容 IE 或低版本浏览器的，可以考虑参考这两个插件） 最低 11
 * https://github.com/vitejs/vite/tree/main/packages/plugin-legacy（官方推荐这个）
 */

import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { buildConfig } from './build/config/buildConfig'
import { serverConfig } from './build/config/serverConfig'
import babel from '@rollup/plugin-babel'

const path = require('path')

export default defineConfig({
  alias: {
    '/@': path.resolve(__dirname, '.', 'src')
  },
  server: serverConfig,
  build: buildConfig,
  optimizeDeps: {
    include: ['lodash', 'echarts', 'axios', 'element-plus']
  },
  plugins: [
    vue(),
    vueJsx(),
    legacy({
      targets: ['defaults', 'not IE 11']
    })
  ],
  rollupInputOptions: {
    plugins: [
      babel({
        presets: [[
          '@babel/preset-env',
          {
            'corejs': 2,
            'useBuiltIns': 'usage',
            'targets': {
              'ie': '11'
            }
          }
        ]]
      })
    ]
  }
})
